<?php


namespace app\admin\controller;


use think\facade\View;
use think\Request;

class Config2 extends Base
{
    protected $ModelPath = 'Config';

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->con = "Config";
        $this->title = "文章";
        $this->pageSize = 15;
        $module = strtolower($this->ModelPath);

        View::assign(array(
            'module'        =>    $module,
            'title'         =>    $this->title,
            'con'           =>    $this->con,
            'pageSize'      =>$this->pageSize
        ));
    }

    public function index()
    {
        return View::fetch();
    }

    public function setting_shop()
    {
        if(request()->isPost()){
//            dd(request()->param());
            $params = request()->param();
            unset($params['file']);
//            dd($params);
            foreach ($params as $key=>$item)
            {
                if (!empty($item))
                {
                    $this->M->where('key', $key)->update(['value'=>$item]);
                }
            }
//            $update = [
//                'id'       =>  input('id'),
//                'name'     =>  input('name'),
//                'type'     =>  input('type'),
//            ];
//
//            $save = $this->M->update($update);
//            if ($save) {
//                $arr['status'] = 1;
//                $arr['msg'] = '修改成功';
//            } else {
//                $arr['status'] = 0;
//                $arr['msg'] = '修改失败';
//            }
//            return $arr;
        }else{
//            $id = input('id');
            $configList = $this->M
                ->append(['key_format'])
                ->whereIn('id', '215,216,217,218,219')
                ->select();
            View::assign(array(
                'config_list'        =>    $configList,
            ));
            return View::fetch();
        }
    }

    public function edit()
    {
        if(request()->isPost()){
//            dd(request()->param());
            $params = request()->param();
            unset($params['file']);
//            dd($params);
            foreach ($params as $key=>$item)
            {
                if (!empty($item))
                {
                    $this->M->where('key', $key)->update(['value'=>$item]);
                }
            }
//            $update = [
//                'id'       =>  input('id'),
//                'name'     =>  input('name'),
//                'type'     =>  input('type'),
//            ];
//
//            $save = $this->M->update($update);
//            if ($save) {
//                $arr['status'] = 1;
//                $arr['msg'] = '修改成功';
//            } else {
//                $arr['status'] = 0;
//                $arr['msg'] = '修改失败';
//            }
//            return $arr;
        }else{
//            $id = input('id');
            $configList = $this->model
//                ->append(['key_format'])
//                ->whereIn('id', '215,216,217,218,219')
                ->select();
            View::assign(array(
                'config_list'        =>    $configList,
            ));
            return View::fetch();
        }
    }
}